package com.example.springbootyaml.bean;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.Email;
import java.util.Date;
import java.util.List;

/**
 *  将yml文件中的配置信息加载到实体类中，使用@ConfigurationProperties注解
 *  prefix = "person" 中的prefix指定yml中的person与其对应
 *
 * 只有在容器中才能使用，所以加上了@Component注解
 */

@Component
@ConfigurationProperties(prefix = "person")
@Validated
public class Person {
    private int age;
    private String name;
    private List<Dog> list;
    private Date birth;
    @Email
    private String email;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Dog> getList() {
        return list;
    }

    public void setList(List<Dog> list) {
        this.list = list;
    }

    public Date getBirth() {
        return birth;
    }

    public void setBirth(Date birth) {
        this.birth = birth;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", list=" + list +
                ", birth=" + birth +
                ", email='" + email + '\'' +
                '}';
    }
}
